package edu.cmu.cs211.exprtree.tests;

import static org.junit.Assert.assertEquals;
import org.junit.Test;
import edu.cmu.cs211.exprtree.ast.ConstantExpression;
import edu.cmu.cs211.exprtree.ast.UnaryExpression;
import edu.cmu.cs211.exprtree.ast.Expression;


public abstract class UnaryExpressionTest extends ExpressionTestUtil {
	public abstract UnaryExpression createExpr(Expression operand);

	@Test
	public void testConstructor() {
		UnaryExpression x = createExpr(ConstantExpression.ONE);
		assertEquals("ONE", ConstantExpression.ONE, x.getOperand());
		UnaryExpression y = createExpr(ConstantExpression.MINUS_ONE);
		assertEquals("MINUS_ONE", ConstantExpression.MINUS_ONE, y.getOperand());
	}

	@Test(expected = NullPointerException.class)
	public void testValueNull() {
		createExpr(null);
	}


	public void toStringTest(String operand) {
		UnaryExpression x1 = createExpr(ConstantExpression.ONE);
		UnaryExpression x2 = createExpr(ConstantExpression.ZERO);
		
		char symbol1 = x1.getOperatorSymbol();
		char symbol2 = x2.getOperatorSymbol();
		String one = ConstantExpression.ONE.toString();
		String zero = ConstantExpression.ZERO.toString();

		assertEquals("toString incorrect", String.format("(%s%s)", symbol1, one), x1
				.toString());
		assertEquals("toString incorrect", String.format("(%s%s)", symbol2, zero), x2
				.toString());
	}

	
}
